using ScriptableObject;
using UnityEngine;

namespace Audio
{
    public class AudioManager : MonoBehaviour
    {
        [Header("事件监听")] public PlayAudioEventSo fxEvent;

        public PlayAudioEventSo bgmEvent;


        [Header("组件")] public AudioSource fxSource;

        public AudioSource bgmSource;


        private void OnEnable()
        {
            fxEvent.OnEventRaised += OnFXEvent;
            bgmEvent.OnEventRaised += OnBGMEvent;
        }

        private void OnDisable()
        {
            fxEvent.OnEventRaised -= OnFXEvent;
            bgmEvent.OnEventRaised -= OnBGMEvent;
        }

        private void OnFXEvent(AudioClip audioClip)
        {
            fxSource.clip = audioClip;
            fxSource.Play();
        }

        private void OnBGMEvent(AudioClip audioClip)
        {
            bgmSource.clip = audioClip;
            bgmSource.Play();
        }
    }
}